package com.siao.example.libaray.component.view
{
	import com.siao.component.Orientation;
	import com.siao.component.scroller.ScrollBar;
	import com.siao.example.common.ui.Layer;
	import com.siao.mvc.View;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * 滚动条视图
	 * @author SiaoLeon
	 */
	public class ComponentScrollbarView extends View
	{
		// -------------------------------------------------------------------------------------------------------- 静态常量
		
		// -------------------------------------------------------------------------------------------------------- 静态变量
		
		// -------------------------------------------------------------------------------------------------------- 静态方法
		
		// -------------------------------------------------------------------------------------------------------- 静态函数
		
		// -------------------------------------------------------------------------------------------------------- 属性
		
		// -------------------------------------------------------------------------------------------------------- 变量
		
		private var scrollbar:ScrollBar;
		
		// -------------------------------------------------------------------------------------------------------- 构造
		
		/**
		 * 构造函数
		 */
		public function ComponentScrollbarView()
		{
			super();
			
			var background:Sprite = new Sprite();
			background.graphics.beginFill(0X000000, 0.8);
			background.graphics.drawRect(0, 0, 20, 100);
			background.graphics.endFill();
			
			var drag:Sprite = new Sprite();
			drag.graphics.beginFill(0XFF0000, 1);
			drag.graphics.drawRect(0, 0, 20, 40);
			drag.graphics.endFill();
			
			var prev:Sprite = new Sprite();
			prev.graphics.beginFill(0XFF0000, 0.8);
			prev.graphics.drawRect(0, 0, 20, 20);
			prev.graphics.endFill();
			
			var next:Sprite = new Sprite();
			next.graphics.beginFill(0XFF0000, 0.8);
			next.graphics.drawRect(0, 0, 20, 20);
			next.graphics.endFill();
			
			this.scrollbar = new ScrollBar(Orientation.VERTICAL, background, drag, prev, next);
			this.scrollbar.setValue(0, 2, 5, 10);
			this.scrollbar.unitDragMode = false;
			this.scrollbar.spacing = 2;
			this.scrollbar.x = 50;
			this.scrollbar.y = 80;
			this.scrollbar.height = 400;
			this.scrollbar.addEventListener(Event.CHANGE, onScrollChange);
		}
		
		// -------------------------------------------------------------------------------------------------------- 方法
		
		override public function onAdd():void
		{
			Layer.instance.content.addChild(scrollbar);
		}
		
		override public function onRemove():void
		{
			this.scrollbar.removeEventListener(Event.CHANGE, onScrollChange);
			
			Layer.instance.content.removeChild(scrollbar);
		}
		
		// -------------------------------------------------------------------------------------------------------- 函数
		
		private function onScrollChange(event:Event):void
		{
			trace(this.scrollbar.current);
		}
	
	}
}
